package cn.zhizihua.service.impl;

import cn.zhizihua.exception.AppException;
import cn.zhizihua.exception.AppExceptionCodeMsg;
import cn.zhizihua.mapper.FoodMapper;
import cn.zhizihua.pojo.Food;
import cn.zhizihua.query.BaseQuery;
import cn.zhizihua.query.FoodQuery;
import cn.zhizihua.service.IFoodService;
import cn.zhizihua.vo.PageBean;
import cn.zhizihua.vo.ResultBean;
import com.alibaba.druid.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *  1、添加@Service 注解
 *  2、装配Mapper层对象
 *  3、进行方法参数校验  事务处理@Transactional
 */
@Service
public class FoodService extends BaseService<Food> implements IFoodService {

    @Autowired
    private FoodMapper foodMapper;

    /*
   根据商家id查询餐品
    */
    @Override
    public ResultBean getByBusinessId(Integer businessId) {
        //参数校验
        if (businessId==null || businessId==0){
            //抛自定义异常 参数为空
            throw new AppException(AppExceptionCodeMsg.PARAMS_EMPTY);
        }

        List<Food> foodList = foodMapper.getByBusinessId(businessId);

        return ResultBean.SUCCESS(foodList);
    }
}
